package net.sxjr.config;

import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;

/*
 * @ClassName: GlobalExceptionHandler
 * @Description: (作为一个控制层的切面处理)
 * @author chenaonan
 * @date 2018年8月17日 下午1:41:38
 */

@RestControllerAdvice
public class GlobalExceptionHandler {
	
	// 所有的异常都是Exception子类
@ExceptionHandler(Exception.class)
	@SuppressWarnings("unused")
	public Object defaultErrorHandler(HttpServletRequest request, RException e) {
		class ErrorInfo {

			private Integer code;

			private String msg;

			private String url;

			public Integer getStatus() {
				return code;
			}

			public void setStatus(Integer status) {
				this.code = status;
			}

			public String getMsg() {
				return msg;
			}

			public void setMsg(String msg) {
				this.msg = msg;
			}

			public String getUrl() {
				return url;
			}

			public void setUrl(String url) {
				this.url = url;
			}
		}

		ErrorInfo info = new ErrorInfo();
		// 标记一个错误信息类型
		//info.setStatus(e.get);
		info.setMsg(e.getMessage());
		info.setUrl(request.getRequestURL().toString());
		info.setStatus(e.getCode());

		return info;
	}

	
}
